<template>
	<div>
		<div class="layout-breadcrumb">
			<Breadcrumb>
			    <BreadcrumbItem to="/">首页</BreadcrumbItem>
			    <BreadcrumbItem href="">系统配置</BreadcrumbItem>
			    <BreadcrumbItem href="/config/sms/tpl">短信模版管理</BreadcrumbItem>
			</Breadcrumb>
		</div>
		<div class="layout-content">
		    <div class="layout-content-main">
		    	<Tabs value="tpl" @on-click="changeTab">
			        <TabPane label="短信模版" name="tpl">
			        	<Tpl ref="tpl"></Tpl>
			        </TabPane>
			        <TabPane label="测试" name="test">
			        	<Test ref="test"></Test>
			        </TabPane>
			    </Tabs>
		    </div>
		</div>
	</div>
</template>
<script>
import {Breadcrumb,Tabs} from 'iview';

import Tpl from 'admin/components/config/sms/tpl';
import Test from 'admin/components/config/sms/test';

export default{
	components:{
        Breadcrumb,
        'BreadcrumbItem' : Breadcrumb.Item,
        Tabs,
        'TabPane' : Tabs.Pane,
        Tpl,
        Test,
    },
    data () {
        return {
        	
        }
    },
    methods:{
    	//测试标签页获取所有模版
    	testTab(){
    		var config_ids = this.$refs.tpl.config_ids;
    		var modules = this.$refs.tpl.modules;
    		this.$refs['test'].formReset();
    		//获取所有模版,并获取服务商和模块名
    		this.Axios.Config.SmsTpl.All()
            .then(res=>{
                var data = res.data;
                this.$refs['test'].smstpls = [];
                var tranData = [];
                //生成服务商短信数组结构
                for(var i in data){
                	var config_id = data[i]['config_id'];
                	var module = data[i]['module'];
                	for(var c in config_ids){
                		if(config_ids[c]['id']==config_id){
                			tranData[config_ids[c]['vue']] = {'id' : config_ids[c]['id'], 'name':config_ids[c]['desc'],'child': new Array()};
                			break;
                		}
                	}
                	
                }
                //服务商短信模版数据赋值
                for(var i in data){
                	var config_id = data[i]['config_id'];
                	var module = data[i]['module'];
                	for(var c in config_ids){
                		if(config_ids[c]['id']==config_id){
                			break;
                		}
                	}
                	for(var m in modules){
                		if(modules[m]['value']==module){
                			data[i]['module_name'] = modules[m]['name'];break;
                		}
                	}
                	tranData[config_ids[c]['vue']]['child'].push(data[i]);
                }
                for(var i in tranData){
                	this.$refs['test'].smstpls.push(tranData[i]);
                }
            })
    	},
    	changeTab(name){
    		if(name=='test'){
    			this.testTab();
    		}
    	},
    },
    created:function(){
    },
    mounted:function(){
        this.$store.dispatch('CHANGE_ROUTE',{name:'短信模版',route:'/config/sms/tpl',action:1,closable:true});
    },
}
</script>